package com.zxq.exchange.register;

import com.zxq.exchange.model.ExchangeDTO;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 通知平台，有消息上报
 */
public class NotifyPlatformRegister {

    static NotifyPlatformRegister notifyPlatformRegister = new NotifyPlatformRegister();

    public static NotifyPlatformRegister getInstance() {
        return notifyPlatformRegister;
    }

    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2,8,30L, TimeUnit.SECONDS,new ArrayBlockingQueue<>(10));
    /**
     * 消息注册监听
     */
    List<INotifyPlatform> registerCenter = new ArrayList<>();

    /**
     * 注册监听服务
     * @param listen
     */
    public void registerNotify(INotifyPlatform listen){
        registerCenter.add(listen);
    }

    /**
     * 消息提醒
     */
    public void notifyMessage(ExchangeDTO exchangeDTO) {
        threadPoolExecutor.execute(() ->{
            registerCenter.forEach(listen -> {
                listen.notifyPlatform(exchangeDTO);
            });
        });
    }





}
